package com.dmp.storm.bolt;

import java.util.Enumeration;
import java.util.Map;
import java.util.Properties;

/**
 * 
 * @author hutao
 *
 */
public class LoadPropertiesBolt extends BaseMapBolt {

	/**
	 *  
	 */
	private static final long serialVersionUID = -8545733333416836695L;
	public String path;
	public static Properties props = new Properties();

	public void setPath(String path) {
		this.path = path;
	}

	public void prepare() {
		if (path == null || path.isEmpty()) {
			path = "load.properties";
		}
		try {
			props.load(this.getClass().getClassLoader()
					.getResourceAsStream(path));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	public Map<String, Object> process(Map<String, Object> map) {
		try {
			Enumeration en = props.propertyNames(); // 得到配置文件的名字
			while (en.hasMoreElements()) {
				String strKey = (String) en.nextElement();
				String strValue = props.getProperty(strKey.trim());
				// System.out.println(strKey + "=" + strValue);
				map.put(strKey.trim(), strValue);
			}

		} catch (Exception e) {
			e.printStackTrace();
		}

		return map;
	}

}
